﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// Pour en savoir plus sur le modèle d'élément Contrôle utilisateur, consultez la page http://go.microsoft.com/fwlink/?LinkId=234236

namespace BlipSansBlop
{
    public sealed partial class Munitions : UserControl
    {
        public long Balles {get; set;}
        public Point Position { get; set; }
        public double Sens { get; set; }
        public Munitions(double X, double Y)
        {
            this.InitializeComponent();
            MainPage.Ammunitions.Children.Add(this);
            this.Position = new Point(X, Y);
            this.Sens = 1;
            Canvas.SetLeft(this, X);
            Canvas.SetTop(this, Y);
            this.Balles = MainPage.rand.Next(100, 400);
            this.BallesTxt.Text = this.Balles.ToString();
        }

        public void ChangeAspect()
        {
            if (this.MuniCompsite.Rotation + Sens > 10) Sens = (-1);
            if (this.MuniCompsite.Rotation + Sens < -10) Sens = 1;
            this.MuniCompsite.Rotation += Sens;

            Canvas.SetLeft(this, Position.X);
            Canvas.SetTop(this, Position.Y);
        }

        public void Update()
        {
            Point test = new Point(Canvas.GetLeft(this) + this.Width / 2, Canvas.GetTop(this) + this.Height / 2);
            if (VisualTreeHelper.FindElementsInHostCoordinates(test, MainPage.Personnages).Contains(Perso.Instance))
            {
                Perso.Balles += this.Balles;
                MainPage.Ammunitions.Children.Remove(this);
            }
        }

    }
}
